//指标分类管理
/* eslint-disable */
import React, { Component } from 'react';
import { connect } from 'dva';
import { Table, Divider, Tag, InputNumber, Input, Select, Button, message, Icon } from 'antd';
import styles from './Scjhgl.less';
import Filtrate from '../../components/common/Filtrate';
import MyPagination from '../../components/common/MyPagination';
import Container from '../../components/common/Container';
import MyTable from '../../components/common/MyTable';
import request from '../../utils//request';
import PublicService from "../../services/PublicService";
import AddModal from './sub/AddModal';
import config from '../../config';
const { Search } = Input;
const { Option } = Select;
let dragingIndex = -1;
const IconFont = Icon.createFromIconfontCN({
    scriptUrl: '//at.alicdn.com/t/font_1589202_7c747i8xu6h.js',
});

class Scjhgl extends Component {
    state = {
        yearMonth:'',
        year:'',
        companyId:'',
        id:'',
        footerShow: true,
        modalTitle: '',
        addModal: false,
        loading: false,
        icTwoId: '',
        options: [],//指标下拉框
        dataSource: [],
        params: {},
        pageSize: 10,
        pageIndex: 1,
        total: 0,
        columns: [
            {
                children: [
                    {
                        title: '指标单位',
                        dataIndex: 'yearMonth',
                        key: 'yearMonth',
                        width: 150,
                        align: 'center',
                    },

                ],
                title: '时间',
            },
            {
                children: [
                    {
                        title: 't',
                        dataIndex: 'rubbish_jc_str',
                        key: 'rubbish_jc_str',
                        width: 150,
                        align: 'center',
                    },

                ],
                title: '垃圾进场量',
            }, {
                dataIndex: 'xbcw',
                children: [
                    {
                        title: 't',
                        dataIndex: 'rubbish_rl_str',
                        key: 'rubbish_rl_str',
                        width: 150,
                        align: 'center',
                    },

                ],
                title: '垃圾焚烧量',
            }, {
                children: [
                    {
                        title: 'KWh',
                        dataIndex: 'fdl_str',
                        key: 'fdl_str',
                        width: 150,
                        align: 'center',
                    },

                ],
                title: '发电量',
            }, {
                children: [
                    {
                        title: 'KWh',
                        dataIndex: 'swdl_str',
                        key: 'swdl_str',
                        width: 150,
                        align: 'center',
                    },

                ],
                title: '上网电量',
            },


            {
                children: [
                    {
                        title: 'KWh',
                        dataIndex: 'zhcydl_2_str',
                        key: 'zhcydl_2_str',
                        width: 200,
                        align: 'center',
                    },

                ],
                title: '综合厂用电量',
            },
            {
                children: [
                    {
                        title: 'KWh',
                        dataIndex: 'zhcydl_1_str',
                        key: 'zhcydl_1_str',
                        width: 100,
                        align: 'center',
                    },

                ],
                title: '综合厂用电率',
            },
            {
                children: [
                    {
                        title: 't',
                        dataIndex: 'grz_str',
                        key: 'grz_str',
                        width: 100,
                        align: 'center',
                    },

                ],
                title: '供热值',
            },
            {
                dataIndex: 'id',
                title: '操作',
                key: 'id9',
                width: 150,
                align: 'center',
                render: (text, record, index) => {
                    return (

                        <span>
                            <a src="javascript:" onClick={this.onPrint.bind(this,record)}>编辑</a>
                        </span>
                    )
                }
            }
        ],
    };

    componentDidMount() {
        this.onSubmit()
    }

    onSubmit = () => {//查询
        const params = this.f1.getForm().getFieldsValue();

        request({
            url: `/sx-client/sx/productionplan/findByCompanyIdAndYear?company=${params.company}&year=${params.year}`,
            method: 'GET',
        }).then(data => {
 
            if (data.rc === 0) {
                this.setState({
                    dataSource: data.ret,
                    params
                })
            } else {
                message.warning(`${data.err}`)
            }
        })

    }

    // 查看按钮
    onPrint = (record) => {
     

        this.setState({
            addModal: true,
            footerShow: true,
            modalTitle: '编辑',
            id:record.id,
            year:record.year,
            yearMonth:record.yearMonth,
            companyId:record.companyId,
            moddleArr: [
                {
                    type: 'input',
                    label: "垃圾进场量",
                    paramName: "rubbish_jc",
                    key: "rubbish_jc_str",
                    initialValue: record.rubbish_jc_str,
                    rules: [{ ...config.reg.required }],
                    style: { width: 270 },
                    // span: 24
                },
                {
                    type: 'input',
                    label: "垃圾焚烧量",
                    paramName: "rubbish_rl",
                    key: "rubbish_rl",
                    initialValue: record.rubbish_rl_str,
                    rules: [{ ...config.reg.required }],
                    style: { width: 270 },
                },
                {
                    type: 'input',
                    label: "发电量",
                    paramName: "fdl",
                    key: "fdl",
                    initialValue: record.fdl_str,
                    rules: [{ ...config.reg.required }],
                    style: { width: 270 },
                },
                {
                    type: 'input',
                    label: "上网电量",
                    paramName: "swdl",
                    key: "swdl",
                    initialValue: record.swdl_str,
                    rules: [{ ...config.reg.required }],
                    style: { width: 270 },
                },
                {
                    type: 'input',
                    label: "综合厂用电量",
                    paramName: "zhcydl_2",
                    key: "zhcydl_2",
                    initialValue: record.zhcydl_2_str,
                    rules: [{ ...config.reg.required }],
                    style: { width: 270 },
                },
                {
                    type: 'input',
                    label: "综合厂用电率",
                    paramName: "zhcydl_1",
                    key: "zhcydl_1",
                    initialValue: record.zhcydl_1_str,
                    rules: [{ ...config.reg.required }],
                    style: { width: 270 },
                },
                {
                    type: 'input',
                    label: "供热值",
                    paramName: "grz",
                    key: "grz",
                    initialValue: record.grz_str,
                    rules: [{ ...config.reg.required }],
                    style: { width: 270 },
                },

            ]
        })





    };









    // modal保存
    ModalOk = (val) => {
        val.id = this.state.id
        val.companyId = this.state.companyId
        val.year = this.state.year
        val.yearMonth = this.state.yearMonth

        request({
            url: `/sx-client/sx/productionplan/updateProductionPlan`,
            method: 'POST',
            data:val
        }).then(data => {
            if(data.rc === 0) {
                message.success('修改成功!')
            }else{
                message.warning(data.err)
            }
            this.setState({
                addModal:false
            })
            this.onSubmit()
        })


    }

    // 取消保存
    ModalCancel = (type) => {
        let t = this;
        t.setState({
            [type]: false,
            modalBtnLoading: false
        })
    };

    //重置
    ResetForm = () => {
        this.setState({
            pageSize: 10,
            pageIndex: 1,
        })
        setTimeout(() => {
            this.onSubmit(1, 10)
        }, 500)
    }

    render() {

        const { options, dataSource, pageSize, pageIndex, total, columns, addModal, modalTitle, footerShow } = this.state

        let width = document.body.clientWidth;
        const height = document.body.clientHeight;
        let containerHeight = '75vh';
        let tableHeight = 330;
        if (width > 1367) {
            tableHeight = 630;
            containerHeight = '83vh';
        }


        const items = [
            {
                type: 'select',
                label: '指标类型',
                paramName: 'company',
                options: [
                    { text: '清能环保', value: '402880e5703d658801703d68a70e0000' },
                    // { text: '再生能源', value: '2' },
                    // { text: '维尔利', value: '3' },
                    // { text: '清运公司', value: '4' },
                ],
            },
            {
                type: 'select',
                label: '时间选取',
                paramName: 'year',
                options: [
                    { text: '2020', value: '2020' },
                    { text: '2019', value: '2019' },
                    { text: '2018', value: '2018' },
                    { text: '2017', value: '2017' },
                ],
            },



        ];
        return (

            <div className={styles.warp}>
                {
                    addModal &&
                    <AddModal
                        // dataTypes={dataTypes}
                        width={600}
                        visible={addModal}
                        title={modalTitle}
                        // modalBtnLoading={modalBtnLoading}
                        footerShow={footerShow}
                        onModalSave={this.ModalOk.bind(this)}
                        onCancel={this.ModalCancel.bind(this, 'addModal')}
                        // selectedChange={this.selectedChange}
                        moddleArr={this.state.moddleArr}

                    />
                }
                <Filtrate
                    items={items}
                    ref={ref => { this.f1 = ref }}
                    submit={this.onSubmit.bind(this, 1, 10)}
                    ResetForm={this.ResetForm}
                />

                <Container
                    style={{ height: containerHeight, position: "relative", overflow: 'auto' }}
                    header={true}
                >

                    <MyTable
                        columns={columns}
                        scroll={{ y: height - tableHeight }}
                        dataSource={PublicService.transformArrayData(dataSource, true, true, pageIndex, pageSize)}
                        pagination={false}
                    />
                    {/* <MyPagination
                        showPage
                        pageSize={pageSize}
                        current={pageIndex}
                        total={total}
                        showSizeChanger
                        showQuickJumper
                        onChange={this.onChangePage.bind(this)}
                        onShowSizeChange={this.onChangePage1.bind(this)}
                    /> */}
                </Container>

            </div>
        )
    }


}

export default connect()(Scjhgl)